package com.juicygames.framework.gamepart;

import com.juicygames.framework.GameAction;

public class ActionForwarder extends GameHandler {
	
	private GamePart target;
	private Class<? extends GameAction> actionToForward;
	
	public ActionForwarder(GamePart target, Class<? extends GameAction> actionToForward) {
		this.actionToForward = actionToForward;
		this.target = target;
	}
	
	public void handle(GameAction action) {
		target.handleAction(action);
	}
	
	public Class<? extends GameAction> getActionClassHandled() {
		return actionToForward;
	}
	
	public boolean equals(Object other) {
		if (!(other instanceof ActionForwarder)) {
			return false;
		}
		ActionForwarder f = (ActionForwarder) other;
		boolean targetsEqual = target == f.target;
		boolean selvesEqual = parent == f.parent;
		boolean actionsEqual = getActionClassHandled() == f.getActionClassHandled();
		return targetsEqual && selvesEqual && actionsEqual;
	}
	
	public boolean equals(ActionForwarder other) {
		return target == other.getTarget() && actionToForward == other.getActionToForward();
	}
	
	public String toString() {
		return String.format("ActionForwarder[target:%s]",target.toString());
	}

	public GamePart getTarget() {
		return target;
	}

	public Class<? extends GameAction> getActionToForward() {
		return actionToForward;
	}

}
